﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Referee:NPC
    {
        public static int nnum = 0;
        public static int pnum = 0;
        public static int num = 0;
        public void begin(string pname , string nname)
        {
            Random ran = new Random();
            Console.WriteLine("开始游戏吗（y / n）");
            char b = char.Parse(Console.ReadLine());
            if (b == 'y')
            {
                while (true)
                {
                    int r = ran.Next(1, 4);
                    Console.WriteLine("请出拳：1.剪刀  2.石头  3.布（输入相应的数字）");
                    int a = int.Parse(Console.ReadLine());
                    Console.WriteLine(pname + "：出拳：" + arr[a]);
                    NPC npc = new NPC(nname);
                    npc.PlayFG();
                    Console.WriteLine(arr[r]);
                    if (arr[a] == "剪刀")
                    {
                        if (arr[r] == "剪刀")
                        {
                            Console.WriteLine("平局啦！嘿嘿，真晦气！");
                        }
                        if (arr[r] == "石头")
                        {
                            Console.WriteLine(pname + "笨蛋，输啦");
                            nnum++;
                        }
                        if (arr[r] == "布")
                        {
                            Console.WriteLine("恭喜" + pname + "，赢啦");
                            pnum++;
                        }
                        num++;
                        Console.WriteLine("要继续游戏吗？（y / n）");
                        char c2 = char.Parse(Console.ReadLine());
                        if (c2 == 'y')
                        {
                        }
                        else if (c2 == 'n')
                        {
                            break;
                        }
                    }
                    if (arr[a] == "石头")
                    {
                        if (arr[r] == "剪刀")
                        {
                            Console.WriteLine("恭喜" + pname + "，赢啦");
                            pnum++;
                        }
                        if (arr[r] == "石头")
                        {
                            Console.WriteLine("平局啦！嘿嘿，真晦气！");
                        }
                        if (arr[r] == "布")
                        {
                            Console.WriteLine(pname + "笨蛋，输啦");
                            nnum++;
                        }
                        num++;
                        Console.WriteLine("要继续游戏吗？（y / n）");
                        char c2 = char.Parse(Console.ReadLine());
                        if (c2 == 'y')
                        {
                        }
                        else if (c2 == 'n')
                        {
                            break;
                        }
                    }
                    if (arr[a] == "布")
                    {
                        if (arr[r] == "剪刀")
                        {
                            Console.WriteLine(pname + "笨蛋，输啦");
                            nnum++;
                        }
                        if (arr[r] == "石头")
                        {
                            Console.WriteLine("恭喜" + pname + "，赢啦");
                            pnum++;
                        }
                        if (arr[r] == "布")
                        {
                            Console.WriteLine("平局啦！嘿嘿，真晦气！");
                        }
                        num++;
                        Console.WriteLine("要继续游戏吗？（y / n）");
                        char c2 = char.Parse(Console.ReadLine());
                        if (c2 == 'y')
                        {
                        }
                        else if (c2 == 'n')
                        {
                            break;
                        }
                    }
                }
                if (nnum > pnum)
                {
                    Console.WriteLine("笨蛋"+pname+","+nname+"赢了");
                }
                else if (pnum > nnum)
                {
                    Console.WriteLine("恭喜"+pname+"赢了");
                }
                else
                {
                    Console.WriteLine("平局啦");
                }
                Console.WriteLine("本轮结束，是否开始下一轮：（y / n）");
                char c1 = char.Parse(Console.ReadLine());
                if (c1 == 'y')
                {
                    begin(pname, nname);
                }
                else if (c1 == 'n')
                {
                    END(pname , nname);
                }
                else
                {
                    Console.WriteLine("你的输入有误！");
                }
            }
            else if(b == 'n')
            {
                Console.WriteLine("已退出！");
            }
            else
            {
                Console.WriteLine("您输入的有误！请重新输入！");
                begin(pname , nname);
            }
        }
        public static void END(string pname , string nname)
        {
            Console.WriteLine("====================================");
            Console.WriteLine(pname + "VS" + nname);
            Console.WriteLine("对战次数："+num);
            Console.WriteLine();
            Console.WriteLine("姓名\t得分");
            Console.WriteLine(pname + "\t" + pnum);
            Console.WriteLine(nname + "\t" + nnum);
            if (pnum>nnum)
            {
                Console.WriteLine(pname+"赢，" +nname+"笨蛋");
            }
            if (nnum>pnum)
            {
                Console.WriteLine(nname+"赢，" +pname+"笨蛋");
            }
            Console.WriteLine("要重新开始游戏吗？（y / n）");
            char c2 = char.Parse(Console.ReadLine());
            if (c2 == 'y')
            {
                num = 0;
                pnum = 0;
                nnum = 0;
                Main(null);
            }
            else if(c2 == 'n')
            {
                Console.WriteLine("已退出！");
            }
            else
            {
                Console.WriteLine("输入错误！默认退出！");
            }
        }
    }
}
